package com.example.music

import android.os.Bundle
import android.os.Handler
import android.os.Looper
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.FrameLayout
import android.widget.Toast
import com.example.music.databinding.ActivityMainBinding
import com.hyjy.music.base.BaseActivity
import com.hyjy.music.fragment.MainFragment
import com.petterp.floatingx.FloatingX
import com.petterp.floatingx.assist.FxDisplayMode
import com.petterp.floatingx.assist.FxScopeType
import com.petterp.floatingx.listener.control.IFxScopeControl
import com.petterp.floatingx.util.createFx

class MainActivity : BaseActivity<ActivityMainBinding>() {

    private val scopeFx: IFxScopeControl by createFx {
        setLayout(R.layout.floating_layout)
        build().toControl(this@MainActivity)
    }

    override fun initViewBinding(layoutInflater: LayoutInflater): ActivityMainBinding {
        return ActivityMainBinding.inflate(layoutInflater)
    }

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        supportFragmentManager.beginTransaction()
            .replace(R.id.fl_container, MainFragment())
            .commit()

//        initCommonFloatView()

//        val control = FloatingX.install {
//            setContext(this@MainActivity)
//            setLayout(R.layout.floating_layout)
//            setScopeType(FxScopeType.APP)
//        }
//        control.setClickListener(300L) {
//            Toast.makeText(this@MainActivity, "111", Toast.LENGTH_SHORT).show()
//        }
//        control.show()
//        Handler(Looper.getMainLooper()).postDelayed({
//            control.move(9_000F, 500F)
//        }, 500L)
//
//        scopeFx.show()
//        scopeFx.configControl.run {
//            setEnableEdgeAdsorption(false)
//        }
//        Handler(Looper.getMainLooper()).postDelayed({
//            scopeFx.move(9_000F, 100F,true)
//        }, 3000L)
    }

    override fun onBackPressed() {
        moveTaskToBack(true)
    }

    private fun initCommonFloatView() {
        val view = View.inflate(this, R.layout.floating_layout, null)
        view.layoutParams = FrameLayout.LayoutParams(20, 20)
        view.setOnClickListener {
            Toast.makeText(this@MainActivity, "123", Toast.LENGTH_SHORT).show()
        }
        val rootView = window.decorView.rootView;
        val contentView = rootView?.findViewById<ViewGroup>(android.R.id.content)
        contentView?.addView(
            view,
            ViewGroup.LayoutParams.WRAP_CONTENT,
            ViewGroup.LayoutParams.WRAP_CONTENT
        )
    }
}